package com.lagou.util;


import com.alibaba.fastjson.JSONObject;

import java.io.IOException;

/**
 * @author HuanyuZhou
 * @date 2020/6/8 10:18
 */
public class JSONSerializer implements Serializer{
    @Override
    //序列化
    public byte[] serialize(Object object) throws IOException {
        byte[] bytes = JSONObject.toJSONBytes(object);
        return bytes;
    }

    @Override
    //反序列化
    public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
       T obejct = JSONObject.parseObject(bytes, clazz);
        return obejct;
    }
}
